package com.service.Impl;
import java.util.ArrayList;
import java.util.List;
import com.dao.ReclamationOrderMapper;
import com.entity.ReclamationOrder;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.ReclamationOrderService;
import com.utils.BaseService;
import com.utils.DataTables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@Service
public class ReclamationOrderServiceImpl extends BaseService implements ReclamationOrderService{
    @Autowired
    private ReclamationOrderMapper reclamationOrderMapper;
    @Override
    public long getReclamationOrderRowCount(){
        return reclamationOrderMapper.getReclamationOrderRowCount();
    }
    @Override
    public List<ReclamationOrder> selectReclamationOrder(){
        return reclamationOrderMapper.selectReclamationOrder();
    }
    @Override
    public ReclamationOrder selectReclamationOrderByObj(ReclamationOrder obj){
        return reclamationOrderMapper.selectReclamationOrderByObj(obj);
    }
    @Override
    public ReclamationOrder selectReclamationOrderById(Integer id){
        return reclamationOrderMapper.selectReclamationOrderById(id);
    }
    @Override
    public int insertReclamationOrder(ReclamationOrder value){
        return reclamationOrderMapper.insertReclamationOrder(value);
    }
    @Override
    public int insertNonEmptyReclamationOrder(ReclamationOrder value){
        return reclamationOrderMapper.insertNonEmptyReclamationOrder(value);
    }
    @Override
    public int insertReclamationOrderByBatch(List<ReclamationOrder> value){
        return reclamationOrderMapper.insertReclamationOrderByBatch(value);
    }
    @Override
    public int deleteReclamationOrderById(Integer id){
        return reclamationOrderMapper.deleteReclamationOrderById(id);
    }
    @Override
    public int updateReclamationOrderById(ReclamationOrder enti){
        return reclamationOrderMapper.updateReclamationOrderById(enti);
    }
    @Override
    public int updateNonEmptyReclamationOrderById(ReclamationOrder enti){
        return reclamationOrderMapper.updateNonEmptyReclamationOrderById(enti);
    }

    public ReclamationOrderMapper getReclamationOrderMapper() {
        return this.reclamationOrderMapper;
    }

    public void setReclamationOrderMapper(ReclamationOrderMapper reclamationOrderMapper) {
        this.reclamationOrderMapper = reclamationOrderMapper;
    }



    @Override
    public DataTables getPageList(DataTables dataTables) {
        PageHelper.startPage((dataTables.getStart() / dataTables.getLength()) + 1, dataTables.getLength()); // 核心分页代码

//        PageHelper.orderBy("sort asc");

        if(!StringUtils.isEmpty(dataTables.getColumn())){
            String column = propertyToColumn(ReclamationOrderMapper.class, dataTables.getColumn());
            if(!StringUtils.isEmpty(column)){
                PageHelper.orderBy(column + " " + dataTables.getOrder());
            }
        }
        System.out.println(dataTables.getSearch());
        PageInfo<ReclamationOrder> pageInfo = new PageInfo<ReclamationOrder>(reclamationOrderMapper.getPageList(dataTables.getSearch(), dataTables.getSubSQL()));
        dataTables.setRecordsTotal(pageInfo.getTotal());
        dataTables.setRecordsFiltered(pageInfo.getTotal());
        dataTables.setData(pageInfo.getList() != null ? pageInfo.getList() : new ArrayList<ReclamationOrder>());

        return dataTables;
    }

}